package com.jinduplan.planmanager.mvp.presenter

import com.cxz.kotlin.baselibs.ext.ss
import com.cxz.kotlin.baselibs.mvp.BasePresenter
import com.cxz.kotlin.baselibs.utils.GsonHelper
import com.fphoenixcorneae.util.toast.ToastUtil
import com.jinduplan.planmanager.bean.HttpResult
import com.jinduplan.planmanager.bean.MessageBean
import com.jinduplan.planmanager.http.MainRetrofit
import com.jinduplan.planmanager.mvp.contract.ProjectContract
import com.jinduplan.planmanager.mvp.model.ProjectModel
import io.reactivex.rxjava3.core.Observable

/**
 * @author admin
 * @date 2018/11/20
 * @desc
 */
class ProjectPresenter : BasePresenter<ProjectContract.Model, ProjectContract.View>(),
    ProjectContract.Presenter {

    override fun createModel(): ProjectContract.Model? = ProjectModel()

    override fun getProjectList(page: Int, limit: Int,project_id:Int,audit_id:Int,audit_status:Int,labour_id:Int) {
        mModel?.getProjectList(page, limit,project_id,audit_id,audit_status,labour_id)?.ss(mModel, mView, page == 1, onSuccess = {
            if (it.code == 200) {
                mView?.setProjectListData(it.data!!)
            }
        }, onError = {
            ToastUtil.show(it.msg)
        })

    }

    override fun readMessage(id: Int, is_read: Int) {
        mModel?.readMessage(id, is_read)?.ss(mModel, mView, true, onSuccess = {
            if (it.code == 200) {
                mView?.readMsgSuccess()
            }
        }, onError = {
            ToastUtil.show(it.msg)
        })
    }

    override fun auditMsg(id: Int, status: Int) {
        mModel?.auditMsg(id, status)?.ss(mModel, mView, true, onSuccess = {
            if (it.code == 200) {
                mView?.auditMsgSuccess()
            }
        }, onError = {
            ToastUtil.show(it.msg)
        })
    }


}